//
//  UIBarButtonItem+Extension.swift
//  XDweibo
//
//  Created by HanXingda on 15/7/1.
//  Copyright © 2015年 韩兴达. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    convenience init(imageName: String,hightImageName: String?) {
        let btn = UIButton()

        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let hImageName = hightImageName ?? imageName + "_highlighted"
        btn.setBackgroundImage(UIImage(named: hImageName), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        self.init(customView:btn)
    }
    
    convenience init(imageName: String,hightImageName: String?,target: AnyObject?,action: String?) {
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let hImageName = hightImageName ?? imageName + "_highlighted"
        btn.setBackgroundImage(UIImage(named: hImageName), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        if action != nil {
        btn.addTarget(target, action:Selector(action!), forControlEvents: UIControlEvents.TouchUpInside)
        }
        self.init(customView:btn)
    }

    
}
